package com.ruoyi.hospital.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hospital.mapper.SchedulesMapper;
import com.ruoyi.hospital.domain.Schedules;
import com.ruoyi.hospital.service.ISchedulesService;

/**
 * 排班信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-07-03
 */
@Service
public class SchedulesServiceImpl implements ISchedulesService
{
    @Autowired
    private SchedulesMapper schedulesMapper;

    /**
     * 查询排班信息
     *
     * @param scheduleId 排班信息主键
     * @return 排班信息
     */
    @Override
    public Schedules selectSchedulesByScheduleId(Long scheduleId)
    {
        return schedulesMapper.selectSchedulesByScheduleId(scheduleId);
    }

    /**
     * 查询排班信息列表
     *
     * @param schedules 排班信息
     * @return 排班信息
     */
    @Override
    public List<Schedules> selectSchedulesList(Schedules schedules)
    {
        return schedulesMapper.selectSchedulesList(schedules);
    }

    /**
     * 新增排班信息
     *
     * @param schedules 排班信息
     * @return 结果
     */
    @Override
    public int insertSchedules(Schedules schedules)
    {
        schedules.setCreateTime(DateUtils.getNowDate());
        return schedulesMapper.insertSchedules(schedules);
    }



    /**
     * 修改排班信息
     *
     * @param schedules 排班信息
     * @return 结果
     */
    @Override
    public int updateSchedules(Schedules schedules)
    {
        schedules.setUpdateTime(DateUtils.getNowDate());
        int result = schedulesMapper.updateSchedules(schedules);
        
        // 更新成功后，重新查询获取最新的医生姓名信息
        if (result > 0) {
            Schedules updatedSchedule = schedulesMapper.selectSchedulesByScheduleId(schedules.getScheduleId());
            if (updatedSchedule != null) {
                schedules.setDoctorName(updatedSchedule.getDoctorName());
                schedules.setDeptName(updatedSchedule.getDeptName());
            }
        }
        
        return result;
    }

    /**
     * 批量删除排班信息
     *
     * @param scheduleIds 需要删除的排班信息主键
     * @return 结果
     */
    @Override
    public int deleteSchedulesByScheduleIds(Long[] scheduleIds)
    {
        return schedulesMapper.deleteSchedulesByScheduleIds(scheduleIds);
    }

    /**
     * 删除排班信息信息
     *
     * @param scheduleId 排班信息主键
     * @return 结果
     */

    public int deleteSchedulesByScheduleId(Long scheduleId)
    {
        return schedulesMapper.deleteSchedulesByScheduleId(scheduleId);
    }
}
